<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>添加新用户</title>
		<link type="text/css" rel="stylesheet" href="layui/css/layui.css" />
		<script type="text/javascript" src="layui/layui.js"></script>
	</head>
	<body>
		<form id="updateRole" class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					roleId:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="roleId" name="roleId" 
						placeholder="请输入用户名" class="layui-input layui-bg-gray" readonly="readonly" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>
					角色名称:
				</label>
				<div class="layui-input-inline">
					<input type="text" id="name" name="name" 
						placeholder="请输入邮箱" class="layui-input" lay-verify="required"/>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button lay-submit class="layui-btn layui-btn-sm" lay-filter="updateRole">更新</button>
					<button type="reset" lay-submit class="layui-btn layui-btn-sm">取消</button>
				</div>
			</div>
		</form>
		
		<script>
		//23d66d84-fae1-45d5-bd07-b694662fe579
		layui.use(['form','layer'],function(){
			var form = layui.form,$ = layui.$,layer = layui.layer;
			// 表单按钮在监听的时候    updateUser按钮后面的（lay-filter事件名字）
			form.on('submit(updateRole)',function(res){
				var str = $("#updateRole").serialize()+"&token=23d66d84-fae1-45d5-bd07-b694662fe579";
				$.post(
					"http://stuapi.ysdjypt.com/api/UpdateRole",
					str,
					function(res){
					   //success: true，操作成功；false,操作失败 
					   if(res.success == true){
					   	 layer.alert("更新成功");
					   	 //先得到当前iframe层的索引
						var index = parent.layer.getFrameIndex(window.name); 
						//再执行关闭 
						parent.layer.close(index);  
						//关闭父级页面的表格
						parent.layui.table.reload('testReload');
					   }else{
					   	layer.alert("更新失败");
					   }
					},
					"json"
				);
				return false;
				
			});
			
			// 表格顶部工具栏 监听    test 是table表属性的监听事件 lay-filter
//			table.on('toolbar(test)',function(res){
//				//   res.event      工具栏按钮里的lay-event
//			})
//			
			form.on('submit(createUser1)',function(res){
				layer.msg("点击了提交");
				//$.post()  
				// form 表单里文本框name属性值要和请求的地址参数一样
				var str = $("#addUser").serialize()+"&token=23d66d84-fae1-45d5-bd07-b694662fe579";
				$.post(
					"http://stuapi.ysdjypt.com/api/CreateUser",//url
					str,//参数
					function(res){
						console.log(res);
						//layer.alert(res.message);
						var success = res.success;// success: true，操作成功；false,操作失败
						console.log(success);
						if(success==true){
							layer.alert("注册成功"+res.message);
						}else{
							layer.alert("注册失败"+res.message);
						}
					},
					"json"
				)
				return false;
			})
		})
		</script>
		
		
	</body>
</html>
